﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace MedicalSelfserviceTerminals
{
    /// <summary>
    /// GetCardWindow.xaml 的交互逻辑
    /// </summary>
    public partial class GetCardWindow : Window
    {
        BackgroundWorker bwReadID = new BackgroundWorker();
        BackgroundWorker bwSend = new BackgroundWorker();

        public GetCardWindow()
        {
            InitializeComponent();
            titleBar.tbFuntxt.Text = "办理一卡通个人信息";
            titleBar.Sec = 15;
            titleBar.WindowClose = WindowClose;

            //读取二代身份证信息  
            //ReadIDCard.Instance.OnReadedInfo += new EventHandler<ReadEventArgs>(readIDCrad_OnReadedInfo);
            //ReadIDCard.Instance.OnReadError += new EventHandler<ReadErrorEventArgs>(readIDCrad_OnReadError);
          

            lbName.Content = string.Empty;
            lbSex.Content = string.Empty;
            lbBirthday.Content = string.Empty;
            lbCardNo.Content = string.Empty;

            lbSendState.Visibility = System.Windows.Visibility.Hidden;
            lbSendBtn.Visibility = System.Windows.Visibility.Hidden;

            bwReadID.WorkerSupportsCancellation = true;
            bwReadID.RunWorkerCompleted += bwReadID_RunWorkerCompleted;
            bwReadID.DoWork += bwReadID_DoWork;

            bwSend.WorkerSupportsCancellation = true;
            bwSend.RunWorkerCompleted += bwSend_RunWorkerCompleted;
            bwSend.DoWork += bwSend_DoWork;

            bwReadID.RunWorkerAsync();
        }

  

        private void Label_MouseLeftButtonDown_1(object sender, MouseButtonEventArgs e)
        {
            if (bwSend.IsBusy)
            {
                return;
            }
            lbSendState.Visibility = System.Windows.Visibility.Visible;
            bwSend.RunWorkerAsync();
        }

        public void WindowClose()
        {
            this.DialogResult = false;
            this.Close();
        }

        private void UCLeftButton_MouseLeftButtonDown_1(object sender, MouseButtonEventArgs e)
        {
            //this.DialogResult = false;
            this.Close();
        }

        private void bwReadID_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
        {
            lbName.Content = "李新华";
            lbSex.Content = "男";
            lbBirthday.Content = "1983-12-03";
            lbCardNo.Content = "61032219831203001X";

            lbSendBtn.Visibility = System.Windows.Visibility.Visible;
            
        }

        private void bwReadID_DoWork(object sender, DoWorkEventArgs e)
        {
            Thread.Sleep(3000);

            //if (!ReadIDCard.Instance.IsRun)
            //{
            //    ReadIDCard.Instance.Start(ReadType.读基本信息);
            //}
        }

        private void bwSend_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
        {

        }

        private void bwSend_DoWork(object sender, DoWorkEventArgs e)
        {
        }

        //private void readIDCrad_OnReadedInfo(object sender, ReadEventArgs e)
        //{
        //    //idinfo = new IDCardInfo();
        //    //idinfo.Name = e.NewHuman.Name;

        //    //idinfo.Address = e.NewHuman.Address;
        //    //idinfo.Sex = e.NewHuman.Gender;
        //    //idinfo.Birthday = e.NewHuman.BirthDay.ToString("yyyy-MM-dd");
        //    //idinfo.Signdate = e.NewHuman.InceptDate;
        //    //idinfo.Number = e.NewHuman.IDCardNo;
        //    //idinfo.Name = e.NewHuman.Name;
        //    //idinfo.People = e.NewHuman.Nation;
        //    //idinfo.ValidDate = e.NewHuman.ExpireDate;

        //    lbName.Content = e.NewHuman.Name;
        //    lbSex.Content = e.NewHuman.Gender;
        //    lbBirthday.Content = e.NewHuman.BirthDay.ToString("yyyy-MM-dd");
        //    lbCardNo.Content = e.NewHuman.IDCardNo;
        //}

        //private void readIDCrad_OnReadError(object sender, ReadErrorEventArgs e)
        //{

        //    MessageBox.Show(e.Error, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);

        //}

        private void Window_Closed(object sender, EventArgs e)
        {
            //ReadIDCard.Instance.OnReadedInfo -= readIDCrad_OnReadedInfo;
            //ReadIDCard.Instance.OnReadError -= readIDCrad_OnReadError;
            //if (!ReadIDCard.Instance.IsRegister)
            //{
            //    ReadIDCard.Instance.Over();
            //}
        }

    }
}
